package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SkplLabel;
import com.ruoyi.system.service.ISkplLabelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标签Controller
 * 
 * @author ruoyi
 * @date 2022-06-15
 */
@RestController
@RequestMapping("/system/label")
public class SkplLabelController extends BaseController
{
    @Autowired
    private ISkplLabelService skplLabelService;

    /**
     * 查询标签列表
     */
    @PreAuthorize("@ss.hasPermi('system:label:list')")
    @GetMapping("/list")
    public TableDataInfo list(SkplLabel skplLabel)
    {
        startPage();
        List<SkplLabel> list = skplLabelService.selectSkplLabelList(skplLabel);
        return getDataTable(list);
    }

    /**
     * 导出标签列表
     */
    @PreAuthorize("@ss.hasPermi('system:label:export')")
    @Log(title = "标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkplLabel skplLabel)
    {
        List<SkplLabel> list = skplLabelService.selectSkplLabelList(skplLabel);
        ExcelUtil<SkplLabel> util = new ExcelUtil<SkplLabel>(SkplLabel.class);
        util.exportExcel(response, list, "标签数据");
    }

    /**
     * 获取标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:label:query')")
    @GetMapping(value = "/{labelId}")
    public AjaxResult getInfo(@PathVariable("labelId") String labelId)
    {
        return AjaxResult.success(skplLabelService.selectSkplLabelByLabelId(labelId));
    }

    /**
     * 新增标签
     */
    @PreAuthorize("@ss.hasPermi('system:label:add')")
    @Log(title = "标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SkplLabel skplLabel)
    {
        return toAjax(skplLabelService.insertSkplLabel(skplLabel));
    }

    /**
     * 修改标签
     */
    @PreAuthorize("@ss.hasPermi('system:label:edit')")
    @Log(title = "标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SkplLabel skplLabel)
    {
        return toAjax(skplLabelService.updateSkplLabel(skplLabel));
    }

    /**
     * 删除标签
     */
    @PreAuthorize("@ss.hasPermi('system:label:remove')")
    @Log(title = "标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{labelIds}")
    public AjaxResult remove(@PathVariable String[] labelIds)
    {
        return toAjax(skplLabelService.deleteSkplLabelByLabelIds(labelIds));
    }
}
